<template>
  <div>
    <div class="filter-line flx-row-s-c">
      <span class="item-name">域名</span>
      <Input
          v-model.trim="dn"
          placeholder=""
          maxlength="30"
          style="width: 150px"
      />
      <span class="item-name">转入状态</span>
      <Select v-model="transferOutStatusSelect" style="width: 150px" clearable>
        <Option
          v-for="item in transferOutStatus"
          :value="item.value"
          :key="item.value"
          >{{ item.label }}</Option
        >
      </Select>

      <div
        class="user-strong-button line-button-size"
        style="margin: 0 10px 0 30px"
        @click="pageChange(1)"
      >
        搜索
      </div>
      <div class="user-normal-button line-button-size" @click="reset">重置</div>
      <!-- <span class="form-font-button">查询转入状态</span> -->
    </div>
    <div class="listTable-area pub-m-t-15">
      <div style="position: relative">
        <Spin :withIcon="true" v-if="loading"></Spin>
        <div class="filter-line search-result-line flx-row-bw-c">
          <span class="c-black f-14"
            >转入列表<span class="c-o">{{
              total != null ? ` (${total}) ` : ""
            }}</span></span
          >
        </div>
        <table class="table-area">
          <thead>
            <tr>
              <th>
                <div class="line-style" style="justify-content: center;min-width: 48px">序号</div>
              </th>
              <th><div class="line-style">域名</div></th>
              <th><div class="line-style">whois邮箱</div></th>
              <th><div class="line-style">提交时间</div></th>
              <th><div class="line-style">转入状态</div></th>
              <th><div class="line-style">操作</div></th>
            </tr>
          </thead>
          <tbody>
            <tr v-for="(item, index) in list" :key="index">
              <td>
                <div class="line-style" style="justify-content: center;">
                  <span class="normal-f" title="">{{
                      index + 1 + (page - 1) * pageSize
                    }}</span>
                </div>
              </td>
              <td>
                <div class="line-style">
                  <span class="c-o f-ell-sin">{{ item.domainName }}</span>
                </div>
              </td>
              <td>
                <div class="line-style">
                  <span class="normal-f f-ell-sin">{{ item.email }}</span>
                </div>
              </td>
              <td>
                <div class="line-style">
                  <span class="normal-f">{{ item.createdTime }}</span>
                </div>
              </td>
              <td>
                <div class="line-style">
                  <span class="normal-f">{{
                    item.status == 1
                      ? "转入中"
                      : item.status == 3
                      ? "过户中"
                      : item.status == 4
                      ? "转入成功"
                      : item.status == 5
                      ? "转入失败"
                      : item.status == 6
                      ? "转移码错误"
                      : "-"
                  }}</span>
                </div>
              </td>
              <td>
                <div class="line-style normal-f">
                  <div
                    class="form-font-button"
                    v-if="item.status == 1"
                    @click="checkStatus(item.id, item.domainName)"
                  >
                    查询转入状态
                  </div>
                  <template v-else-if="item.status == 7">
                    <div class="form-font-button" @click="changeCode(item)">
                      修改转移码
                    </div>
                    <div class="form-font-button" @click="deleteItem(item.id)">
                      取消转入
                    </div>
                  </template>
                  <span v-else class="normal-f">-</span>
                </div>
              </td>
            </tr>
          </tbody>
        </table>
        <Empty-State
          v-if="total != null && total == 0"
          content="未搜索到任何内容！"
        ></Empty-State>
        <div class="form-page-bottom-area flx-row-c-c">
          <Page
            :total="total"
            :current="page"
            :page-size="pageSize"
            :page-size-opts="pageSizeOpts"
            @on-change="pageChange"
            @on-page-size-change="pageSizeChange"
            show-elevator
            show-sizer
            show-total
          />
        </div>
      </div>
    </div>

    <change-transfer-code
      :show.sync="changeTransferCodeShow"
      :info="changeTransferCodeInfo"
      @success="getTransferInList"
    ></change-transfer-code>
  </div>
</template>

<script>
import {
  getTransferInList,
  deleteTransferIn,
  getTransferInStatus,
} from "@/api/user";
export default {
  name: "VipTransferInRecord",
  components: {
    changeTransferCode: () =>
      import("_c/modal/userModal/changeTransferCode/changeTransferCode.vue"),
  },
  data() {
    return {
      loading: false,
      transferOutStatus: [
        {
          value: 1,
          label: "转入中",
        },
        {
          value: 3,
          label: "过户中",
        },
        {
          value: 4,
          label: "转入成功",
        },
        {
          value: 5,
          label: "转入失败",
        },
        // {
        //   value: 6,
        //   label: '用户取消'
        // },
        {
          value: 6,
          label: "转移码错误",
        },
      ],
      transferOutStatusSelect: null,
      dn: "",
      // 分页设置
      total: 0,
      pageSizeOpts: [50, 100, 200],
      pageSize: 50,
      page: 1,
      list: [],
      // 修改转移码
      changeTransferCodeShow: false,
      changeTransferCodeInfo: null,
    };
  },

  mounted() {
    const { tab } = this.$route.query;
    if (tab) {
      this.transferOutStatusSelect = parseInt(tab);
    }
    this.getTransferInList();
  },
  methods: {
    // 获取列表
    async getTransferInList() {
      this.loading = true;
      let data = {
        limit: this.pageSize,
        page: this.page,
      };
      if (this.transferOutStatusSelect != null) {
        data.status = this.transferOutStatusSelect;
      }
      if (this.dn != null && this.dn != "") {
        data.domainName = this.dn;
      }
      let res = await getTransferInList(data);
      if (res.code == 200) {
        if (
          this.page > 1 &&
          res.data.total <= (this.page - 1) * this.pageSize
        ) {
          this.page =
            res.data.total == 0 ? 1 : Math.ceil(res.data.total / this.pageSize);
          this.getTransferInList();
          return;
        }
        this.list = res.data.list;
        this.total = res.data.total;
      }
      this.loading = false;
    },
    // 重置
    reset() {
      this.transferOutStatusSelect = null;
      this.dn = "";
      this.page = 1;
      this.getTransferInList();
    },
    // 切换页码
    pageChange(page) {
      this.page = page;
      this.getTransferInList();
    },
    // 切换pageSize
    pageSizeChange(pageSize) {
      this.pageSize = pageSize;
      this.pageChange(1);
    },
    // 删除模板
    deleteItem(id) {
      this.$Modal.confirm({
        title: "取消确认",
        content: "<p>确定要取消此转入吗？</p>",
        onOk: async () => {
          let res = await deleteTransferIn({
            id: id,
          });
          if (res.code == 200) {
            this.$Message.success("取消成功！");
            this.getTransferInList();
          }
        },
      });
    },
    // 修改转移码
    changeCode(item) {
      this.changeTransferCodeInfo = item;
      this.changeTransferCodeShow = true;
    },
    // 查询转入状态
    async checkStatus(id, dn) {
      this.loading = true;
      let res = await getTransferInStatus({ id: id });
      if (res.code == 200) {
        this.$Modal.info({
          title: `${dn}转入状态`,
          content: res.data,
        });
      }
      this.loading = false;
    },
  },
};
</script>

<style lang="scss" scoped>
.listTable-area {
  padding: 30px;
  position: relative;
  left: -30px;
  width: calc(100% + 60px);
  border-top: 20px solid #f3f6fb;
}
.mg-r-25 {
  margin-right: 25px;
}
.template-icon {
  @include size(16px);
  margin-right: 10px;
  flex-shrink: 0;
}
.c-icon {
  @include bg-setting("t-i-1");
}
.p-icon {
  @include bg-setting("t-i-2");
}
</style>
